import django_filters
from django_filters.rest_framework import FilterSet
from passages.models import Passage
from subjects.models import Subject


class PassageFilter(FilterSet):
    user = django_filters.CharFilter(field_name='user__username')
    category = django_filters.ModelMultipleChoiceFilter(
        label='学科（按住ctrl多选）',
        field_name='category__cate_name',
        to_field_name='cate_name',
        queryset=Subject.objects.all()
    )

    class Meta:
        model = Passage
        fields = ['id', 'author', 'title', 'category']
